package com.lxw.station.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lxw.station.constant.CSDNConstant;
import com.lxw.station.dto.SourceDto;
import com.lxw.station.dto.csdn.CsdnFollow;
import com.lxw.station.dto.csdn.UserCookieDTO;
import com.lxw.station.entity.Article;
import com.lxw.station.entity.CsdnUser;
import com.lxw.station.entity.MyArticle;
import com.lxw.station.entity.Rank;
import com.lxw.station.service.HmacSHA256Util;
import com.lxw.station.service.RestTemplateService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

@Slf4j
@Service
public class CSDNApi {
    private static final RestTemplateService restTemplateService = new RestTemplateService();
    private static final String cookie = "uuid_tt_dd=10_37391217390-1703914696685-444469; UserName=weixin_41883161; UserInfo=df8468dc31a3423c9e3b97d8b3d95433; UserToken=df8468dc31a3423c9e3b97d8b3d95433; UserNick=%E4%B9%9D%E8%BD%AC%E6%88%90%E5%9C%A3; AU=435; UN=weixin_41883161; BT=1703914744977; p_uid=U010000; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22weixin_41883161%22%2C%22scope%22%3A1%7D%7D; historyList-new=%5B%5D; management_ques=1710415186021; weixin_41883161comment_new=1710680056497; c_dl_fref=https://so.csdn.net/so/search; c_dl_prid=1710746696936_259480; c_dl_rid=1710746708346_131010; c_dl_fpage=/download/pla12147111/11005305; c_dl_um=distribute.pc_search_result.none-task-download-2%7Edownload%7Efirst_rank_ecpm_v1%7Erank_v31_ecpm-1-12670758-null-null.269%5Ev2%5Econtrol; FCNEC=%5B%5B%22AKsRol-0pGTJ-GXX-ttKAYm2NqFN5_4nHWUzBvjc0VSIE4Kqx59SGuUEYHwYn-3mXVRgCUzT4pnD_9ST5jd6KZu-TnFQPm8RTFn1657JAIuuqoUhFxa9qORzoZkChQy5vHulEu-fFxJhqTSZCRgD340-_nVwQNxZHw%3D%3D%22%5D%5D; creative_btn_mp=3; c_utm_source=originalprotection; c_first_ref=default; c_first_page=https%3A//www.csdn.net/%3Fydreferer%3DaHR0cHM6Ly93d3cuYmFpZHUuY29tL2xpbms%252FdXJsPXdlenI3Skd6QUJxRkZZZlFRRU85MGhmdFhwaWllTzEyLVA3Mnd5RE5IRm0md2Q9JmVxaWQ9YTkzYzE0MzAwMDAyNTMyZTAwMDAwMDAyNjVmYTJlNzQ%253D; c_segment=5; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1709888967,1710042330,1710636965,1710894715; dc_sid=e32f32995a803e495d56ad7c5f1a23be; dc_session_id=10_1710900535216.812186; c_dsid=11_1710900546591.770194; firstDie=1; c_page_id=default; __gads=ID=e178dd4e39d8ad04:T=1706317465:RT=1710900622:S=ALNI_MYkyVWSlk-Kzbw0VW2ayT8Fdd7uew; __gpi=UID=00000cf0ce6b4c82:T=1706317465:RT=1710900622:S=ALNI_MZEafCfOQxoxIm_c06ogQ91O33nLA; __eoi=ID=9ac79b6815dae14b:T=1706317465:RT=1710900622:S=AA-AfjaAr5lqq4C03q_QgQgjzv38; c_utm_medium=notify.im.blog_flow_coupon3.20240320.a; toolbar_remind_num=3; c_pref=https%3A//i.csdn.net/; c_ref=https%3A//upload.csdn.net/creation/uploadResources%3Fspm%3D1011.2124.3001.5646; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1710903572; log_Id_view=56581; log_Id_click=2959; log_Id_pv=2408; dc_tos=samlqy";

    /**
     * Unicode转义字符转换成汉字
     */
    public static String unicodeToChinese(String text) {
        StringBuilder sb = new StringBuilder();
        int length = text.length();
        for (int i = 0; i < length; i++) {
            char c = text.charAt(i);
            if (c == '\\' && i < length - 1 && text.charAt(i + 1) == 'u') {
                String unicode = text.substring(i + 2, i + 6);
                c = (char) Integer.parseInt(unicode, 16);
                i += 5;
            }
            sb.append(c);
        }
        return sb.toString();
    }


    @SneakyThrows
    public static List<Article> getArticles() {
        List<Article> articleDtos = new ArrayList<>();
        String bashCURL = "curl 'https://blog.csdn.net/community/home-api/v1/get-business-list?page=1&size=20&businessType=blog&orderby=&noMore=false&year=&month=&username=weixin_41883161' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Referer: https://blog.csdn.net/weixin_41883161?type=blog' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36' \\\n" +
                "  -H 'sec-ch-ua: \"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"'";
        String articleListUrl = "https://blog.csdn.net/community/home-api/v1/get-business-list?size=20&businessType=blog&orderby=&noMore=false&year=&month=&username=weixin_41883161&page=";
        HttpHeaders headers = RestTemplateService.getHttpHeaders(bashCURL);
        for (int i = 0; i < 15; i++) {
            String body = restTemplateService.exchange(articleListUrl + (i + 1), HttpMethod.GET, null, headers);
            JSONArray list = JSON.parseObject(body).getJSONObject("data").getJSONArray("list");
            System.out.println(list);
            if (list == null || list.size() == 0) {
                break;
            }
            for (Object o : list) {
                articleDtos.add(JSON.parseObject(JSON.toJSONString(o), Article.class));
            }
            if (list.size() < 20) {
                break;
            } else {
                Thread.sleep(3000);
            }
        }
        log.info("articles:{}", articleDtos);
        return articleDtos;
    }

    @SneakyThrows
    public static MyArticle getMarkdownContent(String id) {
        String ekey = "9znpamsyl2c7cdrr9sas0le9vbc3r6ba";
        String curl = "curl 'https://bizapi.csdn.net/blog-console-api/v1/editor/getArticle?id=136523025' \\\n" +
                "  -H 'authority: bizapi.csdn.net' \\\n" +
                "  -H 'accept: application/json, text/plain, */*' \\\n" +
                "  -H 'accept-language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'cookie: UserName=weixin_41883161; UserInfo=df8468dc31a3423c9e3b97d8b3d95433; UserToken=df8468dc31a3423c9e3b97d8b3d95433; UserNick=%E4%B9%9D%E8%BD%AC%E6%88%90%E5%9C%A3; AU=435; UN=weixin_41883161; BT=1703914744977; p_uid=U010000; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22weixin_41883161%22%2C%22scope%22%3A1%7D%7D; historyList-new=%5B%5D; uuid_tt_dd=10_21307064330-1712106032279-539596; c_segment=12; FCNEC=%5B%5B%22AKsRol-ctFvzrpEae1RFB2xcpPDB32_msu3ieadaYIldR9e69fRdgE0BfW3N8CGAbA4rHtKxjc2JnYDJUDMPqDvcnu8Dm-PcJWlW58D7b6Gkk4Y5QQb-UigcmP31FuIL0sRAWxOSlhlCM-yhSG3kqEyCAIryxPcczg%3D%3D%22%5D%5D; x_dev_cloud_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjcmVkZW50aWFsIjoiIiwiY3NkblVzZXJuYW1lIjoid2VpeGluXzQxODgzMTYxIiwidXNlcklkIjoiNjYxY2MyZTc1ZWMyMTM3YzZjMTQ0OTJhIiwidXNlcm5hbWUiOiJ3ZWl4aW5fNDE4ODMxNjEifQ.IAeFfn_1aJbTgVtsXiVDVcLOvnJvfCDTjGVvK2TSzDo; JSESSIONID=C9C9A31193A46A3E6870870FDD6DA289; SESSION=13af7655-3900-4ba7-b212-77eca7cd11d9; dc_sid=9869bbc6ff67b5bd7f926736e676467f; weixin_41883161comment_new=1713368844776; _clck=1jbjtos%7C2%7Cfl1%7C0%7C1547; firstDie=1; ssxmod_itna=Yq+xgDBDcD0DuiCQGHD8YT4BI7phmfCiijDjE3qGN4poDZDiqAPGhDC88U4h8GOiqe8Wc02mGI70f+5axoQGcDqIW6nyeDHxY=DUg70mbD4SKGwD0eG+DD4DWDmmHDnxAQDjxGp9uXwV=Dm4GWSqDgB4GgejiD0RU9tuiD4qDB+hdDKd29DGYUQnUQEuhtoGG9D0UexBdP7ph9fjcHOGXtdZnxagQDzLHDtqNYvdTDCxtVRkimfBEWlEmTaoQ5lGxqCi+QCix=4TxeY0emz0e5QBDKbxq385DAYGh9uiD===; ssxmod_itna2=Yq+xgDBDcD0DuiCQGHD8YT4BI7phmfCiijDjE4A6W4PtD/fiQDFhG0W2zFuB1GIqk8/rum=TXYiL9IHQj6noGFF9Qgn3K5/3MFC1x4mfFhGvfhItf5cR/d2EStzFd1e16wjLiu7HUKFDpKaDcWC8rAGnBFCdOKrioam9jvmxa2TatDqe0vxEoEx3mTIYiuWHZRrRPcND=PvC=i=24gdtYnWtQKrt0fqfFxj3nBd80fxUpmovI31oEhuyCfTKDdxH0P47NiGLfTaQnkQhqRt3gjqsvFasXmHth=HiaPHdoE48UWxMTuDq0sOTonibtiGSqsnDKH8D5WhIYG3mDQDHARNFjaeDNj+iSk8KdCOq18oFb3o0kwnqaflQjfDCx=jn7Rn12lKuCNaEmrBIS++yjmaMNjf82hHjeYIDrjnKSkH=pQrPdle1iczUeamudip3hkQ7rm2WHy83j+ItMkIPanj1neF6PanothTr1hafPUFS+FPzyfzdTT2wb1=ockUOlFS6PEDDwarDjKDewx4D; tfstk=fBiZxjMwEhKZkQ00TWZ4zWswe1qTfudWimNbnxD0C5VMkjGVgWlAfmMjnqSqeWQcsiAY3Wcrgsb0IFe3x-wMH1VD6wx3njFmfr4GKol4nCU_mhC3x-2AmimqHiymnjpTGdLIBAEYmQOS03MtBDmWXIRQmKDHFV-AY3tSBA2yBeCHVKHekkPYio4gSHx39-7Gsj4iK9VLH-fgnGvEKWe0m-VGj9D3F8QGSrcwLjcOYWzM1Ue_NZXFKzVoI5DsCDX75NHgT3K-Y2rgZnPFmimUQvEl3ySyl7081zNttHsa0v2qTzgwaGlqnY308m5MCbDm6DrT4E9Tz20IPPuesiPIf2oUfcAAyvMUszrIRed_lllZy7UMJBhqL5GmbyfwOSgSdc4EZBsEMrumfkmMt3SPJseHW-nxy-Q4SJeUNpJn5KIRJCIgU9bAky8LL79JeZQYSJeUNpJFkZUE2JPWeLC..; creative_btn_mp=3; c_dl_fref=https://so.csdn.net/so/search; c_dl_prid=1713430191425_873550; c_dl_rid=1713430305196_195118; c_dl_fpage=/download/qq_37314721/10450271; c_dl_um=distribute.pc_search_result.none-task-download-2%7Edownload%7Efirst_rank_ecpm_v1%7Erank_v31_ecpm-3-88765422-null-null.269%5Ev2%5Econtrol; c_utm_source=lb; c_first_ref=default; c_first_page=https%3A//blog.csdn.net/weixin_43784341/article/details/137877655; __gads=ID=e178dd4e39d8ad04:T=1706317465:RT=1713445607:S=ALNI_MYkyVWSlk-Kzbw0VW2ayT8Fdd7uew; __gpi=UID=00000cf0ce6b4c82:T=1706317465:RT=1713445607:S=ALNI_MZEafCfOQxoxIm_c06ogQ91O33nLA; __eoi=ID=9ac79b6815dae14b:T=1706317465:RT=1713445607:S=AA-AfjaAr5lqq4C03q_QgQgjzv38; _clsk=127le19%7C1713449286914%7C2%7C0%7Ci.clarity.ms%2Fcollect; dc_session_id=10_1713485147582.102788; c_dsid=11_1713485152612.315801; c_page_id=default; management_ques=1713486561164; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1710987782,1712541756; fe_request_id=1713489420044_9108_2733401; creativeSetApiNew=%7B%22toolbarImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20230921102607.png%22%2C%22publishSuccessImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20240229024608.png%22%2C%22articleNum%22%3A159%2C%22type%22%3A2%2C%22oldUser%22%3Atrue%2C%22useSeven%22%3Afalse%2C%22oldFullVersion%22%3Atrue%2C%22userName%22%3A%22weixin_41883161%22%7D; log_Id_click=4500; c_pref=https%3A//so.csdn.net/so/search%3Fspm%3D1003.2646.3001.4498%26q%3Dcsdn%2520markdown%25E7%2594%259F%25E6%2588%2590html%26t%3Dblog%26u%3D; c_ref=https%3A//mp.csdn.net/mp_blog/manage/article%3Fspm%3D1018.2226.3001.5448; log_Id_view=92821; dc_tos=sc60xc; log_Id_pv=3980; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1713489457' \\\\\\n" +
                "  -H 'origin: https://mp.csdn.net' \\\n" +
                "  -H 'sec-ch-ua: \"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"' \\\n" +
                "  -H 'sec-fetch-dest: empty' \\\n" +
                "  -H 'sec-fetch-mode: cors' \\\n" +
                "  -H 'sec-fetch-site: same-site' \\\n" +
                "  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36' \\\n" +
                "  -H 'x-ca-key: 203803574' \\\n" +
                "  -H 'x-ca-signature-headers: x-ca-key,x-ca-nonce'";
        HttpHeaders httpHeaders = RestTemplateService.getHttpHeaders(curl);
        String uuid = createUuid();
        String message = "GET\napplication/json, text/plain, */*\n\n\n\nx-ca-key:203803574\nx-ca-nonce:" + uuid + "\n/blog-console-api/v1/editor/getArticle?id=" + id;
        httpHeaders.add("x-ca-nonce", uuid);
        httpHeaders.add("x-ca-signature", HmacSHA256Util.hmacSHA256(ekey, message));
        httpHeaders.add("x-ca-referer", "https://mp.csdn.net/mp_blog/creation/editor/" + id);
        String url = "https://bizapi.csdn.net/blog-console-api/v1/editor/getArticle?id=" + id;
        url = url.replace("${id}", id);
        String exchange = restTemplateService.exchange(url, HttpMethod.GET, httpHeaders);
        return JSON.parseObject(exchange).getObject("data", MyArticle.class);
    }


    private static String createUuid() {
        Random rand = new SecureRandom();
        StringBuilder uuid = new StringBuilder();
        String charList = "abcdefghijklmnopqrstuvwxyz0123456789";
        for (int i = 0; i < 36; i++) {
            if (i == 8 || i == 13 || i == 18 || i == 23) {
                uuid.append("-");
            } else if (i == 14) {
                uuid.append("4");
            } else {
                uuid.append(charList.charAt(rand.nextInt(charList.length())));
            }
        }
        return uuid.toString();
    }


    /**
     * 取消关注
     */
    @SneakyThrows
    public static boolean unFollow(String follow) {

        String url = "https://mp-action.csdn.net/interact/wrapper/pc/fans/v1/api/unFollow";
        // 设置请求头
        HttpHeaders headers = getHttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        String body = "{\"username\":\"weixin_41883161\",\"follow\":\"${follow}\",\"source\":\"ME\",\"fromType\":\"pc\",\"detailSourceName\":\"个人主页\"}";
        body = body.replace("${follow}", follow);
        String responseBody = restTemplateService.exchange(url, HttpMethod.POST, body, headers);
        if (responseBody.contains("您取关已达上限，请24小时后再试。")) {
            return false;
        }
        Thread.sleep(3000);
        return true;

    }

    /**
     * 关注列表
     */
    @SneakyThrows
    public static List<CsdnFollow> getFollowsFromCSDN(String token, String username) {
        String curl = "curl 'https://mp-action.csdn.net/interact/wrapper/pc/fans/v1/api/getFollowOffsetList?pageSize=20&username=weixin_41883161' \\\n" +
                "  -H 'authority: mp-action.csdn.net' \\\n" +
                "  -H 'accept: application/json, text/plain, */*' \\\n" +
                "  -H 'accept-language: zh-CN,zh;q=0.9' \\\n" +
                "  -H 'cookie: " + token + "' \\\n" +
                "  -H 'origin: https://blog.csdn.net' \\\n" +
                "  -H 'referer: https://blog.csdn.net/weixin_41883161?type=sub&subType=watch' \\\n" +
                "  -H 'sec-ch-ua: \"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"' \\\n" +
                "  -H 'sec-fetch-dest: empty' \\\n" +
                "  -H 'sec-fetch-mode: cors' \\\n" +
                "  -H 'sec-fetch-site: same-site' \\\n" +
                "  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.289 Safari/537.36' \\\n" +
                "  --compressed";
        String tmp = "https://mp-action.csdn.net/interact/wrapper/pc/fans/v1/api/getFollowOffsetList?pageSize=20&username=" + username;
        String fanId = null;
        JSONArray follows = new JSONArray();
        while (true) {
            String url = tmp;
            if (StringUtils.hasText(fanId)) {
                url = url + "&fanId=" + fanId;
            }
            // 发送请求
            String exchange = restTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            JSONObject data = JSON.parseObject(exchange).getJSONObject("data");
            follows.addAll(data.getJSONArray("list"));
            fanId = data.getString("fanId");
            if (!StringUtils.hasText(fanId)) {
                break;
            }
            Thread.sleep(3000);
        }
        return follows.toJavaList(CsdnFollow.class);
    }

    /**
     * 获取粉丝列表
     */
    public static List<String> getFansOffsetList() throws InterruptedException {

        String urlT = "https://mp-action.csdn.net/interact/wrapper/pc/fans/v1/api/getFansOffsetList?pageSize=200&username=weixin_41883161";
        String url = "https://mp-action.csdn.net/interact/wrapper/pc/fans/v1/api/getFansOffsetList?pageSize=200&username=weixin_41883161";
        // 设置请求头
        HttpHeaders headers = getHttpHeaders();
        List<String> list = new ArrayList<>();
        while (true) {
            try {
                // 发送请求
                Object exchange = restTemplateService.exchange(url, HttpMethod.GET, null, headers);
                System.out.println("获取粉丝列表:" + exchange);
                JSONObject jsonObject = JSON.parseObject(exchange.toString());
                JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("list");
                String fanId = jsonObject.getJSONObject("data").getString("fanId");
                url = urlT + "&fanId=" + fanId;
                for (int j = 0; j < jsonArray.size(); j++) {
                    JSONObject jsonObject1 = jsonArray.getJSONObject(j);
                    String username = jsonObject1.getString("username");
                    list.add(username);
                }
                if (!StringUtils.hasText(fanId) || jsonArray.size() < 20) {
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            Thread.sleep(3000);
        }
        System.out.println(JSON.toJSONString(list));
        return list;
    }

    public static List<CsdnUser> hotRank() throws InterruptedException {
        String curl = "curl 'https://blog.csdn.net/phoenix/web/blog/hot-rank?page=1&pageSize=25&type=' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Referer: https://blog.csdn.net/rank/list' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"'";
        List<CsdnUser> users = new ArrayList<>();
        String tmp = "https://blog.csdn.net/phoenix/web/blog/hot-rank?";
        for (int i = 0; i < 100; i++) {
            String url = tmp + "page=" + i;
            url = url + "&pageSize=25&type=";
            String body = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            System.out.println("body = " + body);
            JSONArray data = JSON.parseObject(body).getJSONArray("data");
            for (int j = 0; j < data.size(); j++) {
                String nickName = data.getJSONObject(j).getString("nickName");
                String userName = data.getJSONObject(j).getString("userName");
                users.add(new CsdnUser(userName, nickName));
            }
            if (data.size() < 25) {
                return users;
            }
            Thread.sleep(3000);
        }
        return users;
    }

    /**
     * 领域内容榜 日更
     */
    @SneakyThrows
    public static JSONArray getContentRank(String childChannel) {
        String curl = "curl 'https://blog.csdn.net/phoenix/web/blog/hot-rank?page=0&pageSize=25&child_channel=c%2Fc%2B%2B&type=' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Referer: https://blog.csdn.net/rank/list/content' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"'";
        String tmp = "https://blog.csdn.net/phoenix/web/blog/hot-rank";
        JSONArray contentRanks = new JSONArray();
        for (int i = 0; i < 2; i++) {
            String url = tmp + "?page=" + i + "&pageSize=25&child_channel=" + childChannel + "&type=";
            String body = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            JSONArray data = JSON.parseObject(body).getJSONArray("data");
            contentRanks.addAll(data);
            Thread.sleep(3000);
        }
        return contentRanks;
    }

    /**
     * 热门专栏榜 日更
     */
    @SneakyThrows
    public static List<CsdnUser> payolumnRrank() {
        String curl = "curl 'https://blog.csdn.net/phoenix/web/blog/pay-column-rank?page=0&pageSize=20' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Referer: https://blog.csdn.net/rank/list/column' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"'";
        String tmp = "https://blog.csdn.net/phoenix/web/blog/pay-column-rank";
        List<CsdnUser> users = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            String url = tmp + "?page=" + i + "&pageSize=20";
            String body = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            JSONArray jsonArray = JSON.parseObject(body).getJSONObject("data").getJSONArray("payColumnRankListItemList");
            for (int j = 0; j < jsonArray.size(); j++) {
                String nickName = jsonArray.getJSONObject(j).getString("nickName");
                String userName = jsonArray.getJSONObject(j).getString("userName");
                users.add(new CsdnUser(userName, nickName));
            }
            if (jsonArray.size() < 20) {
                return users;
            }
            Thread.sleep(3000);
        }
        return users;
    }

    /**
     * 新晋作者榜 周更
     */
    @SneakyThrows
    public static JSONArray getNewAuthorFromCsdn() {
        String curl = "curl 'https://silkroad.csdn.net/api/v2/assemble/list/channel/search_hot_word?new_hot_flag=1&channel_name=pc_hot_word&size=20&user_name=weixin_41883161&platform=pc&imei=10_37391217390-1710380889126-702416' \\\n" +
                "  -H 'accept: application/json, text/javascript, */*; q=0.01' \\\n" +
                "  -H 'accept-language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'content-type: application/json' \\\n" +
                "  -H 'origin: https://blog.csdn.net' \\\n" +
                "  -H 'referer: https://blog.csdn.net/rank/list/author' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"' \\\n" +
                "  -H 'sec-fetch-dest: empty' \\\n" +
                "  -H 'sec-fetch-mode: cors' \\\n" +
                "  -H 'sec-fetch-site: same-site' \\\n" +
                "  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'";
        String tmp = "https://blog.csdn.net//phoenix/web/v2/rank?page=";
        JSONArray objects = new JSONArray();
        for (int i = 0; i < 5; i++) {
            String url = tmp + (i + 1) + "&pageSize=25&rankType=new_author";
            String body = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            JSONArray jsonArray = JSON.parseObject(body).getJSONObject("data").getJSONArray("list");
            if (!CollectionUtils.isEmpty(jsonArray)) {
                objects.addAll(jsonArray);
            }
            Thread.sleep(3000);
        }
        return objects;
    }

    /**
     * 问答酬金榜
     */
    @SneakyThrows
    public static List<CsdnUser> getRewardRankList() {
        String curl = "curl 'https://bizapi.csdn.net/mp/ask/v1/questions/getRewardRankList?pageNo=2&pageSize=20' \\\n" +
                "  -H 'accept: application/json, text/plain, */*' \\\n" +
                "  -H 'accept-language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'origin: https://blog.csdn.net' \\\n" +
                "  -H 'referer: https://blog.csdn.net/rank/list/ask' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"' \\\n" +
                "  -H 'sec-fetch-dest: empty' \\\n" +
                "  -H 'sec-fetch-mode: cors' \\\n" +
                "  -H 'sec-fetch-site: same-site' \\\n" +
                "  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'x-ca-key: 203930474' \\\n" +
                "  -H 'x-ca-nonce: 0df49a0e-1a83-474d-be2d-7e8fb7835821' \\\n" +
                "  -H 'x-ca-signature: tiszv8cz90XMLBCOwHke0KylCwRn2P14nSamd9DHmt0=' \\\n" +
                "  -H 'x-ca-signature-headers: x-ca-key,x-ca-nonce'";
        String tmp = "https://bizapi.csdn.net/mp/ask/v1/questions/getRewardRankList?pageNo=${page}&pageSize=20";
        List<CsdnUser> users = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            String url = tmp.replace("${page}", i + 1 + "");
            String body = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            JSONArray jsonArray = JSON.parseObject(body).getJSONObject("data").getJSONArray("list");
            for (int j = 0; j < jsonArray.size(); j++) {
                String userName = jsonArray.getJSONObject(j).getString("username");
                String nickName = jsonArray.getJSONObject(j).getString("nickname");
                users.add(new CsdnUser(userName, nickName));
                if (jsonArray.size() < 20) {
                    return users;
                }
            }
            Thread.sleep(3000);
        }

        return null;
    }

    /**
     * 作者周榜
     */
    @SneakyThrows
    public static JSONArray getRankWeeklyAuthorFromCsdn() {
        String curl = "curl 'https://blog.csdn.net/phoenix/web/v2/rank?page=4&pageSize=25&rankType=weekly_author' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Referer: https://blog.csdn.net/rank/list/weekly' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"'";
        String tmp = "https://blog.csdn.net/phoenix/web/v2/rank?page=${page}&pageSize=25&rankType=weekly_author";
        JSONArray jsonArray = new JSONArray();
        for (int i = 0; i < 5; i++) {
            String url = tmp.replace("${page}", String.valueOf(i + 1));
            String body = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            JSONArray list = JSON.parseObject(body).getJSONObject("data").getJSONArray("list");
            if (!CollectionUtils.isEmpty(list)) {
                jsonArray.addAll(list);
            }
            Thread.sleep(3000);
        }
        return jsonArray;
    }

    /**
     * 作者总榜
     */
    @SneakyThrows
    public static List<CsdnUser> totalAuthor() {
        String curl = "curl 'https://blog.csdn.net/phoenix/web/v2/rank?page=4&pageSize=25&rankType=total_author' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Referer: https://blog.csdn.net/rank/list/total' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"'";
        String tmp = "https://blog.csdn.net/phoenix/web/v2/rank?page=${page}&pageSize=25&rankType=total_author";
        List<CsdnUser> users = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            String url = tmp.replace("${page}", String.valueOf(i + 1));
            String body = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            JSONArray jsonArray = JSON.parseObject(body).getJSONObject("data").getJSONArray("list");
            for (int j = 0; j < jsonArray.size(); j++) {
                String userName = jsonArray.getJSONObject(j).getString("userName");
                String nickName = jsonArray.getJSONObject(j).getString("nickName");
                users.add(new CsdnUser(userName, nickName));
                if (jsonArray.size() < 25) {
                    return users;
                }
            }
            Thread.sleep(3000);
        }
        return users;
    }

    /**
     * 历史贡献榜
     */
    @SneakyThrows
    public static List<CsdnUser> historyRank() {
        String curl = "curl 'https://blog.csdn.net/phoenix/web/blog/history-rank?page=3&pageSize=20' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Referer: https://blog.csdn.net/rank/list/historical' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"'";
        String tmp = "https://blog.csdn.net/phoenix/web/blog/history-rank?page=${page}&pageSize=20";
        List<CsdnUser> users = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            String url = tmp.replace("${page}", String.valueOf(i));
            String body = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            JSONArray jsonArray = JSON.parseObject(body).getJSONObject("data").getJSONArray("allRankListItem");
            for (int j = 0; j < jsonArray.size(); j++) {
                String userName = jsonArray.getJSONObject(j).getString("userName");
                String nickName = jsonArray.getJSONObject(j).getString("nickName");
                users.add(new CsdnUser(userName, nickName));
                if (jsonArray.size() < 20) {
                    return users;
                }
            }
            Thread.sleep(3000);
        }

        return users;
    }

    /**
     * 原力榜(总榜) 日更
     */
    @SneakyThrows
    public static JSONArray monthlyInfluence() {
        String curl = "curl 'https://blog.csdn.net/phoenix/web/v2/rank?page=8&pageSize=25&rankType=monthly_influence&type=' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Referer: https://blog.csdn.net/rank/list/force' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"'";
        String tmp = "https://blog.csdn.net/phoenix/web/v2/rank?page=${page}&pageSize=25&rankType=monthly_influence&type=";
        JSONArray jsonArray = new JSONArray();
        for (int i = 0; i < 8; i++) {
            String url = tmp.replace("${page}", String.valueOf(i + 1));
            String body = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            JSONArray list = JSON.parseObject(body).getJSONObject("data").getJSONArray("list");
            if (!CollectionUtils.isEmpty(list)) {
                jsonArray.addAll(list);
            }
            Thread.sleep(3000);
        }
        return jsonArray;
    }

    /**
     * 原力榜(常驻地)
     */
    @SneakyThrows
    public static JSONArray monthlyInfluence4city() {
        String curl = "curl 'https://blog.csdn.net/phoenix/web/v2/rank?page=1&pageSize=25&rankType=monthly_influence&type=city' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Cookie: uuid_tt_dd=10_37391217390-1710380889126-702416; c_adb=1; UN=weixin_41883161; p_uid=U010000; tfstk=fNDI1vM0rwbI13Ndg0KZc84vpheSO29qpgZ-m0BF2JeK28i-qzzUazl_P03Ya7nyxu3s22gUaeT3F3gizHDE8YGGFmmoLH2yxJm3E8L2uKkSxD2opxKU1h7TXcqde-MEzam3E8LwhTC_8D0VmKS4P8K_Burdw8FR9hZTDPBL29ERWhZkzaWkqO8m0F1AGT0B81BcY3xoClLukDi3jlks5WUY6P6-AAZQOrnKpoX3RlHZCSPN4hetmfuLf-9CokGtcJESEnC7P7M3CuGMR6uj-unT12-PZlGS2x23hgpKfJaQMYgODOgxf0h41A-vnJwLJbyn4iTEfvgExAiP21eQLfNjd-Iyitzj6715fSX7fr-6f_flD7BZyFI5PPVLjkp2fh_1ZWEgfr-6f_fu9lqK_ht15_f..; fpv=ce99f0cdfd3ccd3d8e80497469a1e379; _ga_JJBD2VG1H7=GS1.1.1710831331.2.0.1710831331.60.0.0; management_ques=1712126502608; loginbox_strategy=%7B%22taskId%22%3A317%2C%22abCheckTime%22%3A1712456041282%2C%22version%22%3A%22ExpA%22%2C%22nickName%22%3A%22JAVA%E9%A2%86%E5%9F%9F%E4%BC%98%E8%B4%A8%E5%88%9B%E4%BD%9C%E8%80%85%22%2C%22blog-threeH-dialog-expa%22%3A1712393373396%7D; UserName=weixin_41883161; UserInfo=c4555f20d69d42a5adc949e9f7372f03; UserToken=c4555f20d69d42a5adc949e9f7372f03; UserNick=JAVA%E9%A2%86%E5%9F%9F%E4%BC%98%E8%B4%A8%E5%88%9B%E4%BD%9C%E8%80%85; AU=435; BT=1712458001403; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22weixin_41883161%22%2C%22scope%22%3A1%7D%7D; _ga=GA1.1.969171427.1710380893; _ga_7W1N0GEY1P=GS1.1.1712906210.33.0.1712906210.60.0.0; dc_sid=39d465f38fd29b58537266a5082613d4; c_first_ref=default; c_segment=0; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1711003597,1711331132,1712559977,1713251139; _clck=1ki88qw%7C2%7Cfl0%7C0%7C1549; csrfToken=G3U1y7pe2GJpAmXwx1DxsLDJ; firstDie=1; SESSION=c1d9a489-52b7-4d6b-aee4-bd3bcb648c63; c_first_page=https%3A//blog.csdn.net/rank/list; creative_btn_mp=3; weixin_41883161comment_new=1713368844776; dc_session_id=10_1713405711888.502141; c_dsid=11_1713405712835.180903; log_Id_click=234; c_pref=https%3A//blog.csdn.net/rank/list/total; c_ref=https%3A//blog.csdn.net/rank/list/historical; c_page_id=default; log_Id_pv=228; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1713406265; log_Id_view=6637; dc_tos=sc4964' \\\n" +
                "  -H 'Referer: https://blog.csdn.net/rank/list/force?type=city' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"'";
        String tmp = "https://blog.csdn.net/phoenix/web/v2/rank?page=${page}&pageSize=25&rankType=monthly_influence&type=city";
        JSONArray jsonArray = new JSONArray();
        for (int i = 0; i < 4; i++) {
            String url = tmp.replace("${page}", String.valueOf(i + 1));
            String body = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            JSONArray list = JSON.parseObject(body).getJSONObject("data").getJSONArray("list");
            if (!CollectionUtils.isEmpty(list)) {
                jsonArray.addAll(list);
            }
            Thread.sleep(3000);
        }
        return jsonArray;
    }

    /**
     * 新人
     */
    @SneakyThrows
    public static JSONArray new_user_influence() {
        String curl = "curl 'https://blog.csdn.net//phoenix/web/v2/rank?page=4&pageSize=25&rankType=new_user_influence' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Referer: https://blog.csdn.net/rank/list/contributor' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"'";
        String tmp = "https://blog.csdn.net//phoenix/web/v2/rank?page=${page}&pageSize=25&rankType=new_user_influence";
        JSONArray jsonArray = new JSONArray();
        for (int i = 0; i < 4; i++) {
            String url = tmp.replace("${page}", String.valueOf(i + 1));
            String body = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            JSONArray list = JSON.parseObject(body).getJSONObject("data").getJSONArray("list");
            if (!CollectionUtils.isEmpty(list)) {
                jsonArray.addAll(list);
            }
            Thread.sleep(3000);
        }
        return jsonArray;
    }

    /**
     * 领军人物
     */
    @SneakyThrows
    public static List<CsdnUser> leader() {
        String curl = "curl 'https://blog.csdn.net/phoenix/web/v2/rank?rankType=leader&page=3&pageSize=25' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Cookie: uuid_tt_dd=10_37391217390-1710380889126-702416; c_adb=1; UN=weixin_41883161; p_uid=U010000; tfstk=fNDI1vM0rwbI13Ndg0KZc84vpheSO29qpgZ-m0BF2JeK28i-qzzUazl_P03Ya7nyxu3s22gUaeT3F3gizHDE8YGGFmmoLH2yxJm3E8L2uKkSxD2opxKU1h7TXcqde-MEzam3E8LwhTC_8D0VmKS4P8K_Burdw8FR9hZTDPBL29ERWhZkzaWkqO8m0F1AGT0B81BcY3xoClLukDi3jlks5WUY6P6-AAZQOrnKpoX3RlHZCSPN4hetmfuLf-9CokGtcJESEnC7P7M3CuGMR6uj-unT12-PZlGS2x23hgpKfJaQMYgODOgxf0h41A-vnJwLJbyn4iTEfvgExAiP21eQLfNjd-Iyitzj6715fSX7fr-6f_flD7BZyFI5PPVLjkp2fh_1ZWEgfr-6f_fu9lqK_ht15_f..; fpv=ce99f0cdfd3ccd3d8e80497469a1e379; _ga_JJBD2VG1H7=GS1.1.1710831331.2.0.1710831331.60.0.0; management_ques=1712126502608; loginbox_strategy=%7B%22taskId%22%3A317%2C%22abCheckTime%22%3A1712456041282%2C%22version%22%3A%22ExpA%22%2C%22nickName%22%3A%22JAVA%E9%A2%86%E5%9F%9F%E4%BC%98%E8%B4%A8%E5%88%9B%E4%BD%9C%E8%80%85%22%2C%22blog-threeH-dialog-expa%22%3A1712393373396%7D; UserName=weixin_41883161; UserInfo=c4555f20d69d42a5adc949e9f7372f03; UserToken=c4555f20d69d42a5adc949e9f7372f03; UserNick=JAVA%E9%A2%86%E5%9F%9F%E4%BC%98%E8%B4%A8%E5%88%9B%E4%BD%9C%E8%80%85; AU=435; BT=1712458001403; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22weixin_41883161%22%2C%22scope%22%3A1%7D%7D; _ga=GA1.1.969171427.1710380893; _ga_7W1N0GEY1P=GS1.1.1712906210.33.0.1712906210.60.0.0; dc_sid=39d465f38fd29b58537266a5082613d4; c_first_ref=default; c_segment=0; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1711003597,1711331132,1712559977,1713251139; _clck=1ki88qw%7C2%7Cfl0%7C0%7C1549; csrfToken=G3U1y7pe2GJpAmXwx1DxsLDJ; firstDie=1; SESSION=c1d9a489-52b7-4d6b-aee4-bd3bcb648c63; c_first_page=https%3A//blog.csdn.net/rank/list; creative_btn_mp=3; weixin_41883161comment_new=1713368844776; dc_session_id=10_1713405711888.502141; c_dsid=11_1713405712835.180903; creativeSetApiNew=%7B%22toolbarImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20230921102607.png%22%2C%22publishSuccessImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20240229024608.png%22%2C%22articleNum%22%3A155%2C%22type%22%3A2%2C%22oldUser%22%3Atrue%2C%22useSeven%22%3Afalse%2C%22oldFullVersion%22%3Atrue%2C%22userName%22%3A%22weixin_41883161%22%7D; log_Id_click=236; waf_captcha_marker=e2a04117b6be2cd29be05dc1e000877ca9a7db613af63d1012a104708be3af94; c_pref=https%3A//blog.csdn.net/rank/list/force%3Ftype%3Dcity; c_ref=https%3A//blog.csdn.net/rank/list/contributor; c_page_id=default; log_Id_pv=230; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1713407239; dc_tos=sc49hs; log_Id_view=6771' \\\n" +
                "  -H 'Referer: https://blog.csdn.net/rank/list/role' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"'";
        String tmp = "https://blog.csdn.net/phoenix/web/v2/rank?rankType=leader&page=${page}&pageSize=25";
        List<CsdnUser> users = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            String url = tmp.replace("${page}", String.valueOf(i + 1));
            String body = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            JSONArray jsonArray = JSON.parseObject(body).getJSONObject("data").getJSONArray("list");
            for (int j = 0; j < jsonArray.size(); j++) {
                String userName = jsonArray.getJSONObject(j).getString("userName");
                String nickName = jsonArray.getJSONObject(j).getString("nickName");
                users.add(new CsdnUser(userName, nickName));
                if (jsonArray.size() < 20) {
                    return users;
                }
            }
            Thread.sleep(3000);
        }

        return users;
    }

    /**
     * 认可
     */
    @SneakyThrows
    public static List<CsdnUser> approve() {
        String curl = "curl 'https://blog.csdn.net/phoenix/web/v2/rank?rankType=approve&page=4&pageSize=25' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Referer: https://blog.csdn.net/rank/list/approve' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"'";
        String tmp = "https://blog.csdn.net/phoenix/web/v2/rank?rankType=approve&page=${page}&pageSize=25";
        List<CsdnUser> users = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            String url = tmp.replace("${page}", String.valueOf(i + 1));
            String body = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
            JSONArray jsonArray = JSON.parseObject(body).getJSONObject("data").getJSONArray("list");
            for (int j = 0; j < jsonArray.size(); j++) {
                String userName = jsonArray.getJSONObject(j).getString("userName");
                String nickName = jsonArray.getJSONObject(j).getString("nickName");
                users.add(new CsdnUser(userName, nickName));
                if (jsonArray.size() < 20) {
                    return users;
                }
            }
            Thread.sleep(3000);
        }

        return users;
    }

    @SneakyThrows
    public static List<Rank> getRank(String type, int pageSize) {
        String curl = "curl 'https://blog.csdn.net/phoenix/web/v2/rank?page=2&pageSize=25&rankType=total_author' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Referer: https://blog.csdn.net/rank/list/total' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"'";
        String url = "https://blog.csdn.net/phoenix/web/v2/rank?pageSize=200";
        url = url + "&rankType=" + type;
        url = url + "&page=" + pageSize;
        HttpHeaders httpHeaders = RestTemplateService.getHttpHeaders(curl);
        String body = RestTemplateService.exchange(url, HttpMethod.GET, null, httpHeaders);
        JSONArray array = JSON.parseObject(body).getJSONObject("data").getJSONArray("list");
        Thread.sleep(3000);
        return JSON.parseArray(JSON.toJSONString(array), Rank.class);
    }

    private static HttpHeaders getHttpHeaders() {
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Cookie", cookie);
        httpHeaders.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36");
        return httpHeaders;
    }

    public static void saveArticle(MyArticle myArticle) {
        String curl = "curl 'https://bizapi.csdn.net/blog-console-api/v3/mdeditor/saveArticle' \\\n" +
                "  -H 'accept: */*' \\\n" +
                "  -H 'accept-language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'content-type: application/json' \\\n" +
                "  -H 'cookie: uuid_tt_dd=10_37391217390-1710380889126-702416; c_adb=1; p_uid=U010000; _ga_JJBD2VG1H7=GS1.1.1710831331.2.0.1710831331.60.0.0; management_ques=1712126502608; _ga=GA1.1.969171427.1710380893; _ga_7W1N0GEY1P=GS1.1.1712906210.33.0.1712906210.60.0.0; dc_sid=39d465f38fd29b58537266a5082613d4; c_first_ref=default; c_segment=0; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1711003597,1711331132,1712559977,1713251139; weixin_41883161comment_new=1713368844776; c_dl_prid=-; c_dl_rid=1713408005136_938742; c_dl_fref=https://blog.csdn.net/weixin_55305220; c_dl_fpage=/download/weixin_55305220/89160444; c_dl_um=-; ssxmod_itna=Qqj2Y5AIx+xmxDq0dD=QoqCqkihDCCQ7/YfKI7DBwor4iNDnD8x7YDvmIE/I+CbD3wfGqmDmDeFWlA4ER5OtAbENoDU4i8DCkGqosmDYAkDt4DTD34DYDixibkxi5GRD0KDFF5XUZ9Dm4GW9qDgR4GgDCiD0+Uc3wiD4qDB+odDKMiyGDDlGBTYtiQ3t7iDY3d4EMbgK0WK77=DjMiD/3h8h76o6PHYnuWHh=ia3qGyQKGuju2BUeDHCwXM4lY3C+4oloje7EhNt0w4RUDt3ieEfiwxtGx4KYhq07/dGDDA7D+d/+xxD; ssxmod_itna2=Qqj2Y5AIx+xmxDq0dD=QoqCqkihDCCQ7/YfKGD8dcOAxGNvPGazbAfuGCtzhIuWwGXO5RZ+2jN5xn4w5u/6Gbq5XYQwgG8iUI1dwUCR+aqRGQdNnxtvVQyodwROzgb/RgXAnUc2ksxF1OjeTo7mzhaB54+eq61G8YgGqRxrbI2rkhr5bi7eTpCnxGIx7qprknDHs=/7Fg=W4s1WpQaEOk3mH81nLQPW+P/nrPmpYPy5t0aAqxNmPsZF1=ClRcgiu7U9FtPC1hpcyMrLz1woBrau5YEtqZmmTcQiQ5XkyBb1gccFwqXZmmTvIwCIPC/26tp10R6UI1IaqT92DYP7AQt4PDpqiydbDec0UAhT8WCDF6+vx5bBSpOIcnjwC9p6B7bzO=2AMipMDvdyc7mHIiA4VBriT/Y5icykWgtkyb1SQG2=yYM0WWMBQ0a40SrLm=LhNkS=cukIh57Drbb9zhl/xxADkvfY+d7O0FxSUUaFkbiCATIcRShF0RRK40bb3wd3+8z6LrzOqaaTex8iWKbxDKuwqG5GM5kQCHCu19rOZostYr4DLxD2GGDD=; firstDie=1; loginbox_strategy=%7B%22taskId%22%3A317%2C%22abCheckTime%22%3A1713432816128%2C%22version%22%3A%22ExpA%22%2C%22nickName%22%3A%22JAVA%E9%A2%86%E5%9F%9F%E4%BC%98%E8%B4%A8%E5%88%9B%E4%BD%9C%E8%80%85%22%2C%22blog-threeH-dialog-expa%22%3A1712393373396%7D; hide_login=1; UN=baidu_16992441; SESSION=bdb3bb72-45c1-428a-858d-e6c67f642726; creative_btn_mp=2; UserName=baidu_16992441; UserInfo=4e3ead2bae914db385d66c880c1602da; UserToken=4e3ead2bae914db385d66c880c1602da; UserNick=baidu_16992441; AU=F9B; BT=1713488066576; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22baidu_16992441%22%2C%22scope%22%3A1%7D%7D; tfstk=fsaSTaaiKLv7c6NjK0C41xRae13QR8_wOBGLsWLy943892NLtvkrYvrjdWetYDFFZXeb98wrYyNHRXFLK_DFZiPuZ20dQOzC77Vke8QaUyi-DnhaMUp-eR9CON3dQO72CIQEv2EFNNCtlSHmObpK2JHvkxcsw2H-vKKx6xHKJ2eKHqhrtbKpyb3xDbAehXSS976ntLfhunlawxT_irGRhA7iHeLLlbNrB7I9JeUjN0aCoH6Od0rLsc4zTwTmz5ZxkXah6HMIfkUrkzBAWmmLvloQ0LCzBJNYK4zA93HT48uYylOpJSgSpRaxXL6jBzVYSqnVW1NYo8PulWRdJjyZH74-RNCiP4H-lj4FnUHQDkUrq2vRdv4bMzEC4dTZConBAIiMRjMNGstHYpdMfp6vOpMm2jcR7s1XhHm-ijMNGstHx0hmwo5fGKth.; _clck=1ki88qw%7C2%7Cfl2%7C0%7C1549; _clsk=1eexm02%7C1713488734554%7C3%7C0%7Ci.clarity.ms%2Fcollect; dc_session_id=10_1713513016706.433032; c_first_page=https%3A//www.csdn.net/%3Fspm%3D1011.2124.3001.4476; c_dsid=11_1713513018514.689497; c_page_id=default; c_pref=https%3A//blog.csdn.net/baidu_16992441%3Ftype%3Dedu; c_ref=https%3A//mp.csdn.net/mp_blog/manage/article%3Fspm%3D1001.2014.3001.5448; log_Id_pv=298; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1713515042; log_Id_view=8586; dc_tos=sc6l3k; log_Id_click=323' \\\n" +
                "  -H 'origin: https://editor.csdn.net' \\\n" +
                "  -H 'referer: https://editor.csdn.net/' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"' \\\n" +
                "  -H 'sec-fetch-dest: empty' \\\n" +
                "  -H 'sec-fetch-mode: cors' \\\n" +
                "  -H 'sec-fetch-site: same-site' \\\n" +
                "  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'x-ca-key: 203803574' \\\n" +
                "  -H 'x-ca-nonce: 240ffffe-159e-4141-8413-df437b9d1cd3' \\\n" +
                "  -H 'x-ca-signature: usSIk2vFjSLYLWrQxCu9DRuwrbJnOdZsAelLlcHvnVs=' \\\n" +
                "  -H 'x-ca-signature-headers: x-ca-key,x-ca-nonce' \\\n";
        String url = "https://bizapi.csdn.net/blog-console-api/v3/mdeditor/saveArticle";
        HttpHeaders httpHeaders = RestTemplateService.getHttpHeaders(curl);
//        HmacSHA256Dto hmacSHA256Dto = new HmacSHA256Dto();
//        hmacSHA256Dto.setMethod("POST").setAccept("*/*").setContentType("application/json").setXCaNonce("15e68e7e-89a7-4cd6-8b76-d473dfdc9553").setUrl(url);
//        String message = HmacSHA256Util.getMessage(hmacSHA256Dto);
//        httpHeaders.add("x-ca-signature",HmacSHA256Util.hmacSHA256("9znpamsyl2c7cdrr9sas0le9vbc3r6ba", message));
        Map<String, Object> params = new HashMap<>();
        params.put("readType", "public");
        params.put("level", "1");
        params.put("tags", "");
        params.put("status", 2);
        params.put("categories", "");
        params.put("type", "original");
        params.put("original_link", "");
        params.put("authorized_status", false);
        params.put("Description", "");
        params.put("resource_url", "");
        params.put("not_auto_saved", "1");
        params.put("source", "pc_mdeditor");
        params.put("cover_images", new String[]{});
        params.put("cover_type", 1);
        params.put("is_new", 1);
        params.put("vote_id", 0);
        params.put("resource_id", "");
        params.put("pubStatus", "draft");
        params.put("title", myArticle.getTitle());
        params.put("content", myArticle.getContent());
        params.put("markdowncontent", myArticle.getMarkdowncontent());

        String body = JSON.toJSONString(params);
        String exchange = RestTemplateService.exchange(url, HttpMethod.POST, body, httpHeaders);
        String id = JSON.parseObject(exchange).getJSONObject("data").getString("id");
        extracted(id, myArticle.getContent(), myArticle.getTitle());
    }

    private static void extracted(String articleId, String content, String title) {
        String curl = "curl 'https://bizapi.csdn.net/blog/phoenix/console/v1/history-version/save' \\\n" +
                "  -H 'accept: */*' \\\n" +
                "  -H 'accept-language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'content-type: application/json' \\\n" +
                "  -H 'cookie: uuid_tt_dd=10_37391217390-1710380889126-702416; c_adb=1; p_uid=U010000; _ga_JJBD2VG1H7=GS1.1.1710831331.2.0.1710831331.60.0.0; management_ques=1712126502608; _ga=GA1.1.969171427.1710380893; _ga_7W1N0GEY1P=GS1.1.1712906210.33.0.1712906210.60.0.0; dc_sid=39d465f38fd29b58537266a5082613d4; c_first_ref=default; c_segment=0; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1711003597,1711331132,1712559977,1713251139; weixin_41883161comment_new=1713368844776; c_dl_prid=-; c_dl_rid=1713408005136_938742; c_dl_fref=https://blog.csdn.net/weixin_55305220; c_dl_fpage=/download/weixin_55305220/89160444; c_dl_um=-; ssxmod_itna=Qqj2Y5AIx+xmxDq0dD=QoqCqkihDCCQ7/YfKI7DBwor4iNDnD8x7YDvmIE/I+CbD3wfGqmDmDeFWlA4ER5OtAbENoDU4i8DCkGqosmDYAkDt4DTD34DYDixibkxi5GRD0KDFF5XUZ9Dm4GW9qDgR4GgDCiD0+Uc3wiD4qDB+odDKMiyGDDlGBTYtiQ3t7iDY3d4EMbgK0WK77=DjMiD/3h8h76o6PHYnuWHh=ia3qGyQKGuju2BUeDHCwXM4lY3C+4oloje7EhNt0w4RUDt3ieEfiwxtGx4KYhq07/dGDDA7D+d/+xxD; ssxmod_itna2=Qqj2Y5AIx+xmxDq0dD=QoqCqkihDCCQ7/YfKGD8dcOAxGNvPGazbAfuGCtzhIuWwGXO5RZ+2jN5xn4w5u/6Gbq5XYQwgG8iUI1dwUCR+aqRGQdNnxtvVQyodwROzgb/RgXAnUc2ksxF1OjeTo7mzhaB54+eq61G8YgGqRxrbI2rkhr5bi7eTpCnxGIx7qprknDHs=/7Fg=W4s1WpQaEOk3mH81nLQPW+P/nrPmpYPy5t0aAqxNmPsZF1=ClRcgiu7U9FtPC1hpcyMrLz1woBrau5YEtqZmmTcQiQ5XkyBb1gccFwqXZmmTvIwCIPC/26tp10R6UI1IaqT92DYP7AQt4PDpqiydbDec0UAhT8WCDF6+vx5bBSpOIcnjwC9p6B7bzO=2AMipMDvdyc7mHIiA4VBriT/Y5icykWgtkyb1SQG2=yYM0WWMBQ0a40SrLm=LhNkS=cukIh57Drbb9zhl/xxADkvfY+d7O0FxSUUaFkbiCATIcRShF0RRK40bb3wd3+8z6LrzOqaaTex8iWKbxDKuwqG5GM5kQCHCu19rOZostYr4DLxD2GGDD=; firstDie=1; loginbox_strategy=%7B%22taskId%22%3A317%2C%22abCheckTime%22%3A1713432816128%2C%22version%22%3A%22ExpA%22%2C%22nickName%22%3A%22JAVA%E9%A2%86%E5%9F%9F%E4%BC%98%E8%B4%A8%E5%88%9B%E4%BD%9C%E8%80%85%22%2C%22blog-threeH-dialog-expa%22%3A1712393373396%7D; hide_login=1; UN=baidu_16992441; SESSION=bdb3bb72-45c1-428a-858d-e6c67f642726; creative_btn_mp=2; UserName=baidu_16992441; UserInfo=4e3ead2bae914db385d66c880c1602da; UserToken=4e3ead2bae914db385d66c880c1602da; UserNick=baidu_16992441; AU=F9B; BT=1713488066576; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22baidu_16992441%22%2C%22scope%22%3A1%7D%7D; tfstk=fsaSTaaiKLv7c6NjK0C41xRae13QR8_wOBGLsWLy943892NLtvkrYvrjdWetYDFFZXeb98wrYyNHRXFLK_DFZiPuZ20dQOzC77Vke8QaUyi-DnhaMUp-eR9CON3dQO72CIQEv2EFNNCtlSHmObpK2JHvkxcsw2H-vKKx6xHKJ2eKHqhrtbKpyb3xDbAehXSS976ntLfhunlawxT_irGRhA7iHeLLlbNrB7I9JeUjN0aCoH6Od0rLsc4zTwTmz5ZxkXah6HMIfkUrkzBAWmmLvloQ0LCzBJNYK4zA93HT48uYylOpJSgSpRaxXL6jBzVYSqnVW1NYo8PulWRdJjyZH74-RNCiP4H-lj4FnUHQDkUrq2vRdv4bMzEC4dTZConBAIiMRjMNGstHYpdMfp6vOpMm2jcR7s1XhHm-ijMNGstHx0hmwo5fGKth.; _clck=1ki88qw%7C2%7Cfl2%7C0%7C1549; _clsk=1eexm02%7C1713488734554%7C3%7C0%7Ci.clarity.ms%2Fcollect; dc_session_id=10_1713513016706.433032; c_first_page=https%3A//www.csdn.net/%3Fspm%3D1011.2124.3001.4476; c_dsid=11_1713513018514.689497; c_page_id=default; c_pref=https%3A//www.csdn.net/%3Fspm%3D1011.2124.3001.4476; c_ref=https%3A//mp.csdn.net/mp_blog/manage/article%3Fspm%3D1000.2115.3001.5448; log_Id_pv=294; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1713513776; log_Id_view=8479; log_Id_click=315; dc_tos=sc6jpj' \\\n" +
                "  -H 'origin: https://editor.csdn.net' \\\n" +
                "  -H 'referer: https://editor.csdn.net/' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"' \\\n" +
                "  -H 'sec-fetch-dest: empty' \\\n" +
                "  -H 'sec-fetch-mode: cors' \\\n" +
                "  -H 'sec-fetch-site: same-site' \\\n" +
                "  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'x-ca-key: 203803574' \\\n" +
                "  -H 'x-ca-nonce: 486a97bd-c315-4214-ae4d-e84cb8c9d25f' \\\n" +
                "  -H 'x-ca-signature: Lpn+I54Ct2OoC1KobnegKwT+/bMTnY/gaD4dTPrg/VU=' \\\n" +
                "  -H 'x-ca-signature-headers: x-ca-key,x-ca-nonce' \\\n";
        String url = "https://bizapi.csdn.net/blog/phoenix/console/v1/history-version/save";
        Map<String, Object> param = new HashMap<>();
        param.put("articleId", articleId);
        param.put("content", content);
        param.put("title", title);
        param.put("type", 2);
        HttpHeaders httpHeaders = RestTemplateService.getHttpHeaders(curl);
        String exchange = RestTemplateService.exchange(url, HttpMethod.POST, param, httpHeaders);
    }

    /**
     * 一直报错
     */
    @SneakyThrows
    public static List<SourceDto> sourceList(String author) {
        String curl = "curl 'https://blog.csdn.net/community/home-api/v1/get-business-list?page=2&size=20&businessType=download&noMore=false&username=baidu_16992441' \\\n" +
                "  -H 'authority: blog.csdn.net' \\\n" +
                "  -H 'accept: application/json, text/plain, */*' \\\n" +
                "  -H 'accept-language: zh-CN,zh;q=0.9' \\\n" +
                "  -H 'cookie: UserName=weixin_41883161; UserInfo=df8468dc31a3423c9e3b97d8b3d95433; UserToken=df8468dc31a3423c9e3b97d8b3d95433; UserNick=%E4%B9%9D%E8%BD%AC%E6%88%90%E5%9C%A3; AU=435; UN=weixin_41883161; BT=1703914744977; p_uid=U010000; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22weixin_41883161%22%2C%22scope%22%3A1%7D%7D; historyList-new=%5B%5D; uuid_tt_dd=10_21307064330-1712106032279-539596; Hm_lvt_e5ef47b9f471504959267fd614d579cd=1713408305; management_ques=1713486561164; ssxmod_itna=mqIx9DnDBD0DyjDzhD2eEt3+aYYGQPQrsteHDlrxWTeGzDAxn40iDtPoXQ/2l6RihqWDNZuDqaY9GS5pNf4ODaRrFDCPGnDBKhNrWexii9DCeDIDWeDiDG4Gm94GtDpxG=Djjtz1M6xYPDEj5DRpPDuxBGDGP1LaKhDeKD0xTFDQ9hLxDrOrY1H35xkbxPLxG1540HLA3qL=gf6RGzkt8Ex+bODl9UDCI1tKypDB+kl1HGmGiTYexNha33zgxqCiDxwD+HsiG43lhPZCDxqi2DQBjBHlQDirxqF7pDD=; ssxmod_itna2=mqIx9DnDBD0DyjDzhD2eEt3+aYYGQPQrsteD61/OiD0y54i=2DL70AiNkKkn4n4P8QAr2qihe3SMvRNP1Dex=p7D8G3Wm42bhoP+cjKC8yX3MK=YF58Vaf7aIsY49=Z+caws0bmgRh4Pi4=V4fiXi3QyjTQc8MEeVE6fWqL3x+bqcCj9IfT8/moY1kfY6Qdogl2iOCraTa6E0QA+QWYZ8rAsfoKKnpIyCjPp/xe68wHhbm+8IlnHSM5q4nvNCzx60LENwRAG2d2+kuf1Ht3+fabCcxxGC3U6Ax8UkaR7SkBEsbsYjacvmLEptSODEOKElez15jAtcnQ0OAEYi9aUhQXsrUBxvDPpiiwt/4jYKsiD+D=4nvpgww1UFBNAEDpW5s7+GERAew+Z=LBhGrhYgwX=o6QpP9usUbGZK8xnGrDSZxP4aqPw1cR5pUq0YMnmiKe3jd4Yv67nNtKG8W4BRsQGKz=qO0s+TE7UUhePbbGBjI/uk1rLmtUB4xqRFW7GzBYK7VtGTDG2/PDFqD+2DxD=; tfstk=fUrtaXYmN6fGwx70fR_3gCAemxW3kleNv5yWmjcMlWFL38BqmPfavxFQUqmmjNkYJSw4mq2bnnHjOYhjG-ZmhoFEfqziifcxD-PRK_jlqRyZ0c1lZgbUtn7t0jsmc0s4w1ofZ_jnh_ZlFma0hMxn9JGEHA96fSiBAYGICjM_GXgIFYAscmNbd9HrnjtXcfGIRYHo_cWtTdM9Dk4MyFyk6NOBOkHCgbwOinDLvA3tNRZ9cn_SBVh7CXClxdV-R-uY0K-x-RazgYN61sh4vJZ_P71HSfa-H84YNtYZKqEZvjZ14LhQX-EK7yjW9vzQIrZa6KKjQlqokbudhnumAu07P5pVUJishSuzm_-Z1-wz4zmRXQkTR8nd4SEu2JbBZf8p59BpuEusKuZuii4us9l-pbXs5E8qovkKZ9BpuEusLvhlCnT2uqDF.; c_segment=12; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1714117431,1714118766,1714731126,1714954254; fpv=993dea6f7cd4c27a546c8c5ab304a99a; yd_captcha_token=dzp; x_inscode_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjcmVkZW50aWFsIjoiIiwiY3NkblVzZXJuYW1lIjoid2VpeGluXzQxODgzMTYxIiwidXNlcklkIjoiNjYzOTk1YzMyNjE4YzMwODVhYmUwZDViIiwidXNlcm5hbWUiOiJ3ZWl4aW5fNDE4ODMxNjEifQ.It4L9S_EfVc7loT9Kb-KDnhOW0UO2IH8RDTDKMq8_Yg; FCNEC=%5B%5B%22AKsRol8HxL3xKDVvwO3ajFZ_G_kuwMFivuUv63rJz1F8MQAepvLQ_x4ccfcEZpbx52f5BaArwTLiKqifasc-wFOAd-CWE7e5PLqxpe4wkkWRNrDI1E8rxJd6jIm4OEDoRANUyXVVv1m4c3florWNZGEm_xv-WEds-w%3D%3D%22%5D%5D; SESSION=154c694c-530c-4250-a507-f3fd2dd3cc09; weixin_41883161comment_new=1715334918522; dc_sid=02577cd8519dd07074f8384b96a2c498; c_dl_um=-; csrfToken=X4KCGDJh2CyC8HHq4IMX9ffw; toolbar_remind_num=1; fe_request_id=1715582741912_6984_5397381; c_dl_prid=1715414122136_477430; c_dl_rid=1715582754004_965528; c_dl_fref=https://so.csdn.net/so/search; c_dl_fpage=/download/weixin_38696143/13693145; c_hasSub=true; dc_session_id=10_1715646212713.485338; __cf_bm=K0BT.ntEKA9o.j9IYB0XVdNoNsNnEC3ZvS8.nguB1mg-1715647655-1.0.1.1-T0pCEDtJx4xI8B.iTUkxYzjIM9EMoXOprAbIumEMRamVF552xqNmKGd4GS0KMVoa1XDiGM4HR2NtSKqFhDpZOg; creative_btn_mp=3; cf_clearance=1ej8NQk9kLaIu0yvOPfix7_f0C0dAKwsqbdusOMcGos-1715647675-1.0.1.1-yJJBW75SwHoHnczXwKj0FC26hPVrfiOl7mf4yB50gkmQmLLgFROn.mjVpMgIfS4zvbwBhqIJ7PWmWx6d05WlXA; __gads=ID=e178dd4e39d8ad04:T=1706317465:RT=1715647717:S=ALNI_MYkyVWSlk-Kzbw0VW2ayT8Fdd7uew; __gpi=UID=00000cf0ce6b4c82:T=1706317465:RT=1715647717:S=ALNI_MZEafCfOQxoxIm_c06ogQ91O33nLA; __eoi=ID=9ac79b6815dae14b:T=1706317465:RT=1715647717:S=AA-AfjaAr5lqq4C03q_QgQgjzv38; _clck=1jbjtos%7C2%7Cflr%7C0%7C1547; c_pref=default; c_ref=default; c_first_ref=default; c_first_page=https%3A//blog.csdn.net/baidu_16992441%3Fspm%3D1010.2135.3001.5421; c_dsid=11_1715648087597.844926; c_page_id=default; log_Id_pv=5558; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1715648089; creativeSetApiNew=%7B%22toolbarImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20230921102607.png%22%2C%22publishSuccessImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20240229024608.png%22%2C%22articleNum%22%3A178%2C%22type%22%3A2%2C%22oldUser%22%3Atrue%2C%22useSeven%22%3Afalse%2C%22oldFullVersion%22%3Atrue%2C%22userName%22%3A%22weixin_41883161%22%7D; log_Id_view=126636; log_Id_click=6450; _clsk=oicyt6%7C1715648097876%7C3%7C0%7Cu.clarity.ms%2Fcollect; dc_tos=sdgaq1' \\\n" +
                "  -H 'referer: https://blog.csdn.net/baidu_16992441?type=download' \\\n" +
                "  -H 'sec-ch-ua: \"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"' \\\n" +
                "  -H 'sec-fetch-dest: empty' \\\n" +
                "  -H 'sec-fetch-mode: cors' \\\n" +
                "  -H 'sec-fetch-site: same-origin' \\\n" +
                "  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.289 Safari/537.36' \\\n" +
                "  --compressed";
        String tmp = "https://blog.csdn.net/community/home-api/v1/get-business-list?page=${page}&size=20&businessType=download&noMore=false&username=${username}";
        int page = 1;
        HttpHeaders httpHeaders = RestTemplateService.getHttpHeaders(curl);
//        httpHeaders.add("Cookie", token);
        List<SourceDto> result = new ArrayList<>();
        while (true) {
            String url = tmp.replace("${page}", String.valueOf(page)).replace("${username}", author);
            log.info(url);
            String exchange = RestTemplateService.exchange(url, HttpMethod.GET, null, httpHeaders);
            log.info("获取资源列表成功:{}", exchange);
            JSONArray list = JSON.parseObject(exchange).getJSONObject("data").getJSONArray("list");
            result.addAll(list.toJavaList(SourceDto.class));
            page++;
            if (list.size() < 20) {
                log.info("总资源量:{}", result.size());
                return result;
            }
            Thread.sleep(3000);
        }
    }

    @SneakyThrows
    public static String getSource(String sourceId) {
        String token = "uuid_tt_dd=10_37391217390-1710380889126-702416; c_adb=1; p_uid=U010000; _ga_JJBD2VG1H7=GS1.1.1710831331.2.0.1710831331.60.0.0; management_ques=1712126502608; _ga=GA1.1.969171427.1710380893; _ga_7W1N0GEY1P=GS1.1.1712906210.33.0.1712906210.60.0.0; dc_sid=39d465f38fd29b58537266a5082613d4; c_first_ref=default; c_segment=0; csrfToken=G3U1y7pe2GJpAmXwx1DxsLDJ; weixin_41883161comment_new=1713368844776; c_dl_um=-; Hm_lvt_e5ef47b9f471504959267fd614d579cd=1713408266; Hm_lpvt_e5ef47b9f471504959267fd614d579cd=1713408266; fpv=c1c52400ef8a6e4d5dcdc690ad5d0591; loginbox_strategy=%7B%22taskId%22%3A317%2C%22abCheckTime%22%3A1713432816128%2C%22version%22%3A%22ExpA%22%2C%22nickName%22%3A%22JAVA%E9%A2%86%E5%9F%9F%E4%BC%98%E8%B4%A8%E5%88%9B%E4%BD%9C%E8%80%85%22%2C%22blog-threeH-dialog-expa%22%3A1712393373396%7D; UN=baidu_16992441; UserName=baidu_16992441; UserInfo=4e3ead2bae914db385d66c880c1602da; UserToken=4e3ead2bae914db385d66c880c1602da; UserNick=baidu_16992441; AU=F9B; BT=1713488066576; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22baidu_16992441%22%2C%22scope%22%3A1%7D%7D; baidu_16992441comment_new=1713730274216; yd_captcha_token=ycvu4E9Hoyo7Sqy+mgBkd/fNBP1Wl7LdOwFIk3hnSWPs21lXaUTbyQDQxC3va3cKH4m/fwPa8SvrfRb9vJBqaw%3D%3D; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1712559977,1713251139; c_first_page=https%3A//public-download.csdn.net/500.html; ssxmod_itna=YqfODvxAxI2tGH3iQ0oBIoqmwbODGOM80bo84GXo4YDZDiqAPGhDC4b/ee8DjDnhdEYD+rN4Djxn3NQdjCcGdkb2mHoDHxY=DU2AWeDxOq0rD74irDDxD3DbfdDSDWKD9D0RSBc6yKGWDmRzDYyFDQ5Gq4DFn6FOe4i7DD5Qkx075SKYDG5Ys3+73j2GDinFebypR2iETQ28D7yhDlPxn4R8TFM6GAHE6/8GEWKDXaQDvOvw21oDUBKsyP7N3mR4iGaeej4qTCi5Kpm4i0ib87/Dorpe702eog0KFisPGDDWTDbPpQhDD===; ssxmod_itna2=YqfODvxAxI2tGH3iQ0oBIoqmwbODGOM80bgDA=nwd4QDkDBk84x7phydk9yoiOeW7qidojhoKp+e9GWKwxPal4gp7qCbQLcOMYtOBeOTtWmFy0Qs+PngUymIW2UfwaFcgCZTSb06zRl+k8ncP+Oyan0DtQzyxI=xx11G1ezad9BAQnhqCQzgQUrYW9e8shSK7j6arbZHQe2Aj1c36yOkso68AgR8sLtDqu73tkiiQffL+Xpe0Z2003Vk28QCLZ486Tb8jCuSyMtWXbc=hBA0Kowm=RBICqj/mM9HG24s6tSBayUOj+6w1EX8apxnL435Oim49Lh706heM1dDKdKPo/2YZ0XH2KyjX7x=fovLltr+mqjUeUt1E0/i2aZ2u1vbbXfhb8+QObbNpeNb67fEUBuORUzFn1fdc=60CTHc2+DnkrIEYWfSQvz5G=X1be3f3VE334jrUUapcf1xWDG272x9DYWnMD+5oGPXGkhMQSwx5mIfdbD2eD08DiQiYD==; tfstk=fNerdPvTtTBPb4VnuqMEu4rzGlH-OAQ_qJgIxkqnV40od0GFYzaKZJMWFWSUoyyIta3SYWu4l79IE0q0mqzkdbaQLSpUXke52vs-euHKKN_1CJr82vHlk1BuLjqmbDXBE00uj9QcrN_1Ct1kmv7P5WwHon0qvqmoxXAl0xmEbvmoKvjqoDo9tU4nKirmkDuHrQAoommK42cy5y4J3qllyl3nzU8Dyq0gq4q7V-boZQErupv33SlrS9u2Kp2q4oHDHFvNOVVtPfgTot9rLomUufNP7LzUxlFngJ8lVPq3y-k-Q6s-_SVb1bPVrpubFDliKj-HKok3ZX2EIOYqDSq7t8UyYpm8FRGEWjSHpXM0CfVgzHITmYm3JfeCWL3uxleT1AWyW0P0bxSrcenDizeLaeAEZmnq5iSDw4KHqjUr80dp9j5x0VsOXBdKZmnq5iS29Bh4Bmu1XGC..; SESSION=4ee09eb9-0e33-4709-b5af-b23bc8c82a32; dc_session_id=11_1714088916164.909973; c_dsid=11_1714088916165.808839; firstDie=1; c_dl_fref=https://blog.csdn.net/baidu_16992441; _clck=1ki88qw%7C2%7Cfl9%7C0%7C1549; c_dl_fpage=/download/baidu_16992441/89212451; creativeSetApiNew=%7B%22toolbarImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20231011044944.png%22%2C%22publishSuccessImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20240229024608.png%22%2C%22articleNum%22%3A0%2C%22type%22%3A0%2C%22oldUser%22%3Afalse%2C%22useSeven%22%3Atrue%2C%22oldFullVersion%22%3Afalse%2C%22userName%22%3A%22baidu_16992441%22%7D; c_dl_prid=1714092424768_792478; c_dl_rid=1714092428706_295568; _clsk=xc6eqt%7C1714092429985%7C8%7C0%7Ct.clarity.ms%2Fcollect; log_Id_click=717; c_pref=https%3A//blog.csdn.net/baidu_16992441%3Ftype%3Ddownload; c_ref=https%3A//i.csdn.net/; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1714092658; log_Id_view=16197; waf_captcha_marker=fab0fa3d4de179396374ca103a38ed56868cdf53872007ea09bc73de3625820f; c_page_id=default; dc_tos=sciyd0; log_Id_pv=594";
        String curl = "curl 'https://download.csdn.net/api/source/detail/v1/download' \\\n" +
                "  -H 'Accept: application/json, text/plain, */*' \\\n" +
                "  -H 'Accept-Language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'Connection: keep-alive' \\\n" +
                "  -H 'Content-Type: application/json' \\\n" +
                "  -H 'Cookie: uuid_tt_dd=10_37391217390-1710380889126-702416; c_adb=1; p_uid=U010000; _ga_JJBD2VG1H7=GS1.1.1710831331.2.0.1710831331.60.0.0; management_ques=1712126502608; _ga=GA1.1.969171427.1710380893; _ga_7W1N0GEY1P=GS1.1.1712906210.33.0.1712906210.60.0.0; dc_sid=39d465f38fd29b58537266a5082613d4; c_first_ref=default; c_segment=0; weixin_41883161comment_new=1713368844776; https_waf_cookie=4ab203a6-6fba-4d3907219fed63e903c6ef7e15eb29827af3; c_dl_um=-; Hm_lvt_e5ef47b9f471504959267fd614d579cd=1713408006; csrfToken=H6H1d2T2zB7Q18YE3ZCwsuPQ; loginbox_strategy=%7B%22taskId%22%3A317%2C%22abCheckTime%22%3A1713432816128%2C%22version%22%3A%22ExpA%22%2C%22nickName%22%3A%22JAVA%E9%A2%86%E5%9F%9F%E4%BC%98%E8%B4%A8%E5%88%9B%E4%BD%9C%E8%80%85%22%2C%22blog-threeH-dialog-expa%22%3A1712393373396%7D; UN=baidu_16992441; UserName=baidu_16992441; UserInfo=4e3ead2bae914db385d66c880c1602da; UserToken=4e3ead2bae914db385d66c880c1602da; UserNick=baidu_16992441; AU=F9B; BT=1713488066576; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22baidu_16992441%22%2C%22scope%22%3A1%7D%7D; baidu_16992441comment_new=1713730274216; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1712559977,1713251139; Hm_lpvt_e5ef47b9f471504959267fd614d579cd=1713938474; ssxmod_itna=YqfODvxAxI2tGH3iQ0oBIoqmwbODGOM80bo84GXo4YDZDiqAPGhDC4b/ee8DjDnhdEYD+rN4Djxn3NQdjCcGdkb2mHoDHxY=DU2AWeDxOq0rD74irDDxD3DbfdDSDWKD9D0RSBc6yKGWDmRzDYyFDQ5Gq4DFn6FOe4i7DD5Qkx075SKYDG5Ys3+73j2GDinFebypR2iETQ28D7yhDlPxn4R8TFM6GAHE6/8GEWKDXaQDvOvw21oDUBKsyP7N3mR4iGaeej4qTCi5Kpm4i0ib87/Dorpe702eog0KFisPGDDWTDbPpQhDD===; ssxmod_itna2=YqfODvxAxI2tGH3iQ0oBIoqmwbODGOM80bgDA=nwd4QDkDBk84x7phydk9yoiOeW7qidojhoKp+e9GWKwxPal4gp7qCbQLcOMYtOBeOTtWmFy0Qs+PngUymIW2UfwaFcgCZTSb06zRl+k8ncP+Oyan0DtQzyxI=xx11G1ezad9BAQnhqCQzgQUrYW9e8shSK7j6arbZHQe2Aj1c36yOkso68AgR8sLtDqu73tkiiQffL+Xpe0Z2003Vk28QCLZ486Tb8jCuSyMtWXbc=hBA0Kowm=RBICqj/mM9HG24s6tSBayUOj+6w1EX8apxnL435Oim49Lh706heM1dDKdKPo/2YZ0XH2KyjX7x=fovLltr+mqjUeUt1E0/i2aZ2u1vbbXfhb8+QObbNpeNb67fEUBuORUzFn1fdc=60CTHc2+DnkrIEYWfSQvz5G=X1be3f3VE334jrUUapcf1xWDG272x9DYWnMD+5oGPXGkhMQSwx5mIfdbD2eD08DiQiYD==; tfstk=fNerdPvTtTBPb4VnuqMEu4rzGlH-OAQ_qJgIxkqnV40od0GFYzaKZJMWFWSUoyyIta3SYWu4l79IE0q0mqzkdbaQLSpUXke52vs-euHKKN_1CJr82vHlk1BuLjqmbDXBE00uj9QcrN_1Ct1kmv7P5WwHon0qvqmoxXAl0xmEbvmoKvjqoDo9tU4nKirmkDuHrQAoommK42cy5y4J3qllyl3nzU8Dyq0gq4q7V-boZQErupv33SlrS9u2Kp2q4oHDHFvNOVVtPfgTot9rLomUufNP7LzUxlFngJ8lVPq3y-k-Q6s-_SVb1bPVrpubFDliKj-HKok3ZX2EIOYqDSq7t8UyYpm8FRGEWjSHpXM0CfVgzHITmYm3JfeCWL3uxleT1AWyW0P0bxSrcenDizeLaeAEZmnq5iSDw4KHqjUr80dp9j5x0VsOXBdKZmnq5iS29Bh4Bmu1XGC..; SESSION=4ee09eb9-0e33-4709-b5af-b23bc8c82a32; dc_session_id=11_1714088916164.909973; firstDie=1; _clck=1ki88qw%7C2%7Cfl9%7C0%7C1549; c_pref=default; c_first_page=https%3A//blog.csdn.net/weixin_41883161%3Ftype%3Ddownload; c_dsid=11_1714092814963.192121; c_dl_fref=https://blog.csdn.net/weixin_41883161; c_ref=https%3A//blog.csdn.net/weixin_41883161%3Ftype%3Ddownload; c_dl_fpage=/download/weixin_41883161/89220238; creativeSetApiNew=%7B%22toolbarImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20231011044944.png%22%2C%22publishSuccessImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20240229024608.png%22%2C%22articleNum%22%3A0%2C%22type%22%3A0%2C%22oldUser%22%3Afalse%2C%22useSeven%22%3Atrue%2C%22oldFullVersion%22%3Afalse%2C%22userName%22%3A%22baidu_16992441%22%7D; c_page_id=default; log_Id_pv=600; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1714093788; _clsk=1waqu1x%7C1714093788160%7C4%7C1%7Ct.clarity.ms%2Fcollect; c_dl_prid=1714093786632_898973; c_dl_rid=1714093789402_676972; dc_tos=sciz8m; log_Id_click=728; log_Id_view=16482' \\\n" +
                "  -H 'Origin: https://download.csdn.net' \\\n" +
                "  -H 'Referer: https://download.csdn.net/download/weixin_41883161/89220238?spm=1001.2014.3001.5503' \\\n" +
                "  -H 'Sec-Fetch-Dest: empty' \\\n" +
                "  -H 'Sec-Fetch-Mode: cors' \\\n" +
                "  -H 'Sec-Fetch-Site: same-origin' \\\n" +
                "  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36' \\\n" +
                "  -H 'X-Tingyun: c=B|jcyC7WVM7Ho;x=bcbd463bf0804fef' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"' \\\n" +
                "  --data-raw '{\"sourceId\":89220238}'";
        String url = "https://download.csdn.net/api/source/detail/v1/download";
        Map<String, String> param = new HashMap<>();
        param.put("sourceId", sourceId);
        String exchange = RestTemplateService.exchange(url, HttpMethod.POST, param, RestTemplateService.getHttpHeaders(curl));
        log.info("获取资源成功:{}", exchange);
        return JSON.parseObject(exchange).getString("data");
    }

    @SneakyThrows
    public static Boolean checkFavoriteByUrl(String sourceUrl) {
        String curl = "curl 'https://mp-action.csdn.net/interact/wrapper/pc/favorite/v1/api/checkFavoriteByUrl?url=https://download.csdn.net/download/weixin_41883161/89212219' \\\n" +
                "  -H 'accept: */*' \\\n" +
                "  -H 'accept-language: zh-CN,zh;q=0.9,en;q=0.8' \\\n" +
                "  -H 'cookie: uuid_tt_dd=10_37391217390-1710380889126-702416; c_adb=1; p_uid=U010000; _ga_JJBD2VG1H7=GS1.1.1710831331.2.0.1710831331.60.0.0; management_ques=1712126502608; _ga=GA1.1.969171427.1710380893; _ga_7W1N0GEY1P=GS1.1.1712906210.33.0.1712906210.60.0.0; dc_sid=39d465f38fd29b58537266a5082613d4; c_first_ref=default; c_segment=0; weixin_41883161comment_new=1713368844776; c_dl_um=-; loginbox_strategy=%7B%22taskId%22%3A317%2C%22abCheckTime%22%3A1713432816128%2C%22version%22%3A%22ExpA%22%2C%22nickName%22%3A%22JAVA%E9%A2%86%E5%9F%9F%E4%BC%98%E8%B4%A8%E5%88%9B%E4%BD%9C%E8%80%85%22%2C%22blog-threeH-dialog-expa%22%3A1712393373396%7D; UN=baidu_16992441; SESSION=bdb3bb72-45c1-428a-858d-e6c67f642726; UserName=baidu_16992441; UserInfo=4e3ead2bae914db385d66c880c1602da; UserToken=4e3ead2bae914db385d66c880c1602da; UserNick=baidu_16992441; AU=F9B; BT=1713488066576; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22baidu_16992441%22%2C%22scope%22%3A1%7D%7D; baidu_16992441comment_new=1713730274216; c_utm_source=lb; toolbar_remind_num=1; _clck=1ki88qw%7C2%7Cfl7%7C0%7C1549; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1712559977,1713251139; c_pref=default; dc_session_id=10_1713936211116.356997; creativeSetApiNew=%7B%22toolbarImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20231011044944.png%22%2C%22publishSuccessImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20240229024608.png%22%2C%22articleNum%22%3A0%2C%22type%22%3A0%2C%22oldUser%22%3Afalse%2C%22useSeven%22%3Atrue%2C%22oldFullVersion%22%3Afalse%2C%22userName%22%3A%22baidu_16992441%22%7D; c_first_page=https%3A//download.csdn.net/download/weixin_41883161; c_dsid=11_1713938473847.800358; ssxmod_itna=YqAxcD9D2A0=eD5DQDXY3fTxIxmuK+AOMOw87M3qGNPq3DZDiqAPGhDC++tf8i8Gxoi8jbAEGYmn+DhpoHf7iwtLFF2eGLDmKDy9QG4e3D445GwD0eG+DD4DWDmWHDnxAQDjxGp9uXwV=Dm4GWSqDg94GgejiD0RU9tuiD4qDBmOdDKdrBmDDlmYWoSGQ4SAiDY8dq6dTS9DaK8qDMbeGXQ0Fo8LRkua4/iPFKKCpuDB6wxBQlGCUQx0PBldXxNhGa3G4sKuGF9ixYS0E=iGD33vwR5Dxfj0xNWDh=QAwQ9/zoDD3PmDw3WGDD==; ssxmod_itna2=YqAxcD9D2A0=eD5DQDXY3fTxIxmuK+AOMOw87M4A=aAoD/SYSDFrmGIgbS6hKAPenKlbBNCehDn00H37/T2D8kS6m8rGY6zjErhoXfGMFpV7FcHH+KyfIok6=aXahmLeh+kjOBm29yCRrW=vcmOUxnK5+HQR=I4IaqrCnAW=FAsH/wNetAT3lATTPWTQAYFkfOAKboEAxf7287a3GwhiU7Lw+86jfEU8zM+WKjEy4ITixjpqkSRI8mIiTEz=6xL9pfnIfIiiR16WMeyW/IEIpjqF89++ko1rqVvqCyULVq2tpzyA8UVX7qiEKaEzDr1frsBThYfsgdaP8dKlzre1A4balsNmb=mbPbh2wwA44ZD3vf3mB3KYGCwm=GaenoP83+Q3NqYTOp10Q3EqXDPBm3fDDw2qDjKDeT44D===; tfstk=f7sihC95pN8_zlkYsMx_YHpF4AaLfftXHsnvMnd48BRCDCnOH-fcM_8VXCFfowfhZmdaGhhVo61QCiKZXmqcC1YY1I8ZLvJ2nqJNmtiD3t5bCIe_JO66cnP8wiqRCOM85P8Y9nyVLgQU63Z82O6wERaITuejKTv6GI-27E8EYB9m0f5279keOK9q_KoaK9RB3now0nlETKvvgI-qZTgwwi7PY8L7r2W2V1SHIezdQB5Pe-pMSQWwt7Pdxo8MaORn07C3neODOgPL-91R71pCiuVH4a1hmU-0jb9G8Txe63riCQS9nTQcE7cvdN5GYEjLhP6hmCYPbeDgQOx23s8cR7mJIhQHrGb_hXWNwCbyftHu69Yl-U9e8x0wXaBRcUSajbOpPKfHyNVoj_SyK2urItnXL-IElqTwdpA5qkm6_pf6Bay3K4BX7p9WwJ2nlqTwdpA8KJ0R5FJBFQC..; c_dl_fref=https://blog.csdn.net/weixin_41883161; c_dl_fpage=/download/weixin_41883161/89212219; c_ref=https%3A//blog.csdn.net/weixin_41883161%3Ftype%3Ddownload; c_page_id=default; log_Id_pv=511; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1713938496; _clsk=ptannj%7C1713938496799%7C9%7C1%7Ck.clarity.ms%2Fcollect; c_dl_prid=1713938492606_308262; c_dl_rid=1713938495909_683364; log_Id_view=13589; log_Id_click=598; dc_tos=scfnga' \\\n" +
                "  -H 'origin: https://download.csdn.net' \\\n" +
                "  -H 'referer: https://download.csdn.net/download/weixin_41883161/89212219?spm=1001.2014.3001.5503' \\\n" +
                "  -H 'sec-ch-ua: \"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"' \\\n" +
                "  -H 'sec-ch-ua-mobile: ?0' \\\n" +
                "  -H 'sec-ch-ua-platform: \"Windows\"' \\\n" +
                "  -H 'sec-fetch-dest: empty' \\\n" +
                "  -H 'sec-fetch-mode: cors' \\\n" +
                "  -H 'sec-fetch-site: same-site' \\\n" +
                "  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'";
        String url = "https://mp-action.csdn.net/interact/wrapper/pc/favorite/v1/api/checkFavoriteByUrl?url=${sourceUrl}";
        url = url.replace("${sourceUrl}", sourceUrl);
        String exchange = RestTemplateService.exchange(url, HttpMethod.GET, null, RestTemplateService.getHttpHeaders(curl));
        log.info("检查收藏成功:{}", exchange);
        JSONObject data = JSONObject.parseObject(exchange).getJSONObject("data");
        for (String key : data.keySet()) {
            if (!"0".equals(data.getString(key))) {
                return true;
            }
        }
        Thread.sleep(200);
        return false;
    }

    /**
     * @param username 当前用户
     * @param follow   将要关注的人
     * @param cookie   当前用户的cookie
     */
    @SneakyThrows
    public static String follow(String username, String follow, String cookie) {
        String url = "https://mp-action.csdn.net/interact/wrapper/pc/fans/v1/api/follow";
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.set("Cookie", cookie);
        // 构造请求实体
        String body = "{\"username\":\"${username}\",\"follow\":\"${follow}\",\"source\":\"ME\",\"fromType\":\"pc\",\"detailSourceName\":\"个人主页\"}";
        body = body.replace("${follow}", follow).replace("${username}", username);
        Object exchange = RestTemplateService.exchange(url, HttpMethod.POST, body, headers);
        log.info("关注成功:" + exchange);
        String response = exchange.toString();
        if (response.contains("上限")) {
            throw new RuntimeException("关注失败");
        }
        Thread.sleep(1000);
        return response;
    }

    /**
     * 获取指定用户的cookie
     * @param userName
     * @return
     */
    @SneakyThrows
    public static String getUserCookie(String userName) {
        return new String(Files.readAllBytes(Paths.get("src/main/resources/cookies/" + userName)), StandardCharsets.UTF_8);
    }

    @SneakyThrows
    public static List<UserCookieDTO> getUserCookieDTOs() {
        List<UserCookieDTO> list = new ArrayList<>();
        for (File file : new File("src/main/resources/cookies/").listFiles()) {
            String username = file.getName();
            String cookie = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
            list.add(new UserCookieDTO(username, cookie));
        }
        return list;
    }

    /**
     * 点赞
     */
    public static void like(String id, String cookie) {
        String url = "https://blog.csdn.net//phoenix/web/v1/article/like";
        HttpHeaders httpHeaders = getHttpHeaders(cookie);
        httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
        body.add("articleId", id);
        Object exchange = RestTemplateService.exchange(url, HttpMethod.POST, body, httpHeaders);
        if (exchange.toString().contains("已达上限")) {
            throw new RuntimeException(exchange.toString());
        }
        log.info("点赞成功:" + exchange);

    }

    /**
     * 评论
     */
    @SneakyThrows
    public static String comment(String id, String myUsername, String cookie) {
        userstatus(myUsername, cookie);
        String url = "https://blog.csdn.net/phoenix/web/v1/comment/submit";
        HttpHeaders httpHeaders = getHttpHeaders(cookie);
        httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        MultiValueMap<String, String> body = new LinkedMultiValueMap<>();
        body.add("articleId", id);
//        String content = "哇塞！你的技术类文章真是别有一番风味啊！看似枯燥的技术细节，被你写得如此生动有趣，真是让人拍案叫绝，已三连支持，欢迎大佬回访戳这里回访:https://blog.csdn.net/weixin_41883161/article/details/136614485";
        String content;
        if (CSDNConstant.MY_USERNAME.equals(myUsername)) {
            content = "文章别有一番风味！让人拍案叫绝，已三连支持，欢迎大佬回访";
        } else {
            content = "文章别有一番风味！让人拍案叫绝，已三连支持，欢迎大佬戳这里回访:https://blog.csdn.net/weixin_41883161/article/details/139551524";
        }
        body.add("content", content);
        Object exchange = RestTemplateService.exchange(url, HttpMethod.POST, body, httpHeaders);
        if (exchange.toString().contains("上限")) {
            throw new RuntimeException(exchange.toString());
        }
        log.info("评论成功:" + exchange);
        return exchange.toString();
    }


    /**
     * 评论前获取用户状态
     */
    @SneakyThrows
    public static void userstatus(String username, String cookie) {
        String url = "https://passport.csdn.net/v1/api/check/userstatus";
        HttpHeaders httpHeaders = getHttpHeaders(cookie);
        String body = "{\"username\":\"${username}\",\"biz\":\"blog\",\"subBiz\":\"other_service\"}";
        body = body.replace("${username}", username);
        httpHeaders.setContentType(MediaType.APPLICATION_JSON);
        Object exchange = RestTemplateService.exchange(url, HttpMethod.POST, body, httpHeaders);
        log.info("userstatus = " + exchange);
        Thread.sleep(200);
    }

    private static HttpHeaders getHttpHeaders(String cookie) {
        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.add("Cookie", cookie);
        httpHeaders.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36");
        httpHeaders.add("Origin", "https://blog.csdn.net");
        return httpHeaders;
    }

    @SneakyThrows
    public static void main(String[] args) {
        String baidu_16992441 = getUserCookie("baidu_16992441");
        System.out.println(baidu_16992441);
    }


}
